package org.frog.sgs.server.msg;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.frog.sgs.card.basic.Basic;
import org.frog.sgs.card.equipment.Equipment;
import org.frog.sgs.card.scheme.type.JudgeType;
import org.frog.sgs.character.Character;
import org.frog.sgs.event.SgsEventCode;
import org.frog.sgs.io.SgsMsg;

/**
 * @author duanxiangqi
 * @date 2012-10-26
 */
public class ServerMsgSyncAllCharacterInfo extends SgsMsg {

	private static final long serialVersionUID = -3194850296731511971L;

	public ServerMsgSyncAllCharacterInfo(List<Character> characters) {
		super(SgsEventCode.SYNC_ALL_CHARACTER_INFO);
		try {
			writeInt(characters.size());
			for (Character character : characters) {
				writeInt(character.getPosition());
				writeBoolean(character.getRole().isZhugong());
				writeBoolean(character.isDie());
				if (character.isDie() || character.getRole().isZhugong()) {
					writeInt(character.getRole().getId());
				}
				writeInt(character.getGeneral().getId());
				writeInt(character.getStrength().getStrength());
				writeInt(character.getCardsInHand().size());
				Map<Integer, Equipment> equipments = character.getEquipments();
				writeInt(equipments.size());
				for (Integer position : character.getEquipments().keySet()) {
					writeInt(position);
					writeInt(character.getEquipments().get(position).getId());
				}
				Map<JudgeType, Basic> judgeSchemes = character.getJudgeSchemes();
				writeInt(judgeSchemes.size());
				for (JudgeType judgeType : judgeSchemes.keySet()) {
					writeInt(judgeType.getValue());
					writeInt(judgeSchemes.get(judgeType).getId());
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
